// JavaScript Document

/*function check()
{
	//Check First name
	var FName = document.getElementById("firstname").value;
	if(!(/^[A-Za-z]+[^0-9][^@,!,#,$,%,^, ,&,*,(,),¢,£,¥,§,©,®]$/.test(FName)))
	{
		document.getElementById("showMsgFN").innerHTML = "Can be [A-Z a-z and _ ] only";
		document.getElementById("clearMsg").innerHTML = "";
		return false; 
	}
	else
	{
		document.getElementById("showMsgFN").innerHTML = "";
	}
	
	//Check Last name
	var LName = document.getElementById("lastname").value;
	if(!(/^[A-Za-z]+[^0-9][^@,!,#,$,%,^, ,&,*,(,),¢,£,¥,§,©,®]$/.test(LName)))
	{
		document.getElementById("showMsgLN").innerHTML = "Can be [A-Z a-z and _ ] only";
		document.getElementById("clearMsg").innerHTML = "";
		return false; 
	}
	else
	{
		document.getElementById("showMsgLN").innerHTML = "";
	}
	
	//Check phone
	var Phone = document.getElementById("phone").value;
	if(!(/^[0-9]{1,12}$/.test(Phone)))
	{
		document.getElementById("showMsgPhone").innerHTML = "Just from 1 to 12 DIGIT number only";
		document.getElementById("clearMsg").innerHTML = "";
		return false; 
	}
	else
	{
		document.getElementById("showMsgPhone").innerHTML = "";
	}
	
	//Check DOB
	var DOB = document.getElementById("DOB").value;
	var year=Number(DOB.substr(0,4));
	var month=Number(DOB.substr(5,2));
	var day=Number(DOB.substr(8,2));
	var today=new Date();
	var age=today.getFullYear()-year;
	
	if(today.getMonth()<month || (today.getMonth()==month && today.getDate()<day) || (today.getMonth()==month && today.getDate()==day))
	{
		if(age < 12)
		{
			document.getElementById("showMsgDOB").innerHTML = "Not enough age, must be 12+";
			document.getElementById("clearMsg").innerHTML = "";
			return false; 
		}
		else
		{
			document.getElementById("showMsgDOB").innerHTML = "";
		}
	}
	
	//Check ID Card
	var idcard = document.getElementById("idcard").value;
	if(!(/^[0-9]{1,9}$/.test(idcard)))
	{
		document.getElementById("showMsgIDcard").innerHTML = "Just from 1 to 9 DIGIT number only";
		document.getElementById("clearMsg").innerHTML = "";
		return false; 
	}
	else
	{
		document.getElementById("showMsgIDcard").innerHTML = "";
	}
	
	//Check Address
	var address = document.getElementById("address").value;
	if(!(/[^@,!,#,$,%,^,&,*,(,),¢,£,¥,§,©,®]$/.test(address)))
	{
		document.getElementById("showMsgAddress").innerHTML = "Cannot be @,!,#,$,%,^";
		document.getElementById("clearMsg").innerHTML = "";
		return false; 
	}
	else
	{
		document.getElementById("showMsgAddress").innerHTML = "";
	}
	
	//Check City
	var city = document.getElementById("city").value;
	if(!(/[^@,!,#,$,%,^,&,*,(,),¢,£,¥,§,©,®]$/.test(city)))
	{
		document.getElementById("showMsgCity").innerHTML = "Cannot be @,!,#,$,%,^";
		document.getElementById("clearMsg").innerHTML = "";
		return false; 
	}
	else
	{
		document.getElementById("showMsgCity").innerHTML = "";
	}
	
	//Check Job
	var job = document.getElementById("job").value;
	if(!(/[^@,!,#,$,%,^,&,*,(,),¢,£,¥,§,©,®]$/.test(job)))
	{
		document.getElementById("showMsgJob").innerHTML = "Cannot be @,!,#,$,%,^";
		document.getElementById("clearMsg").innerHTML = "";
		return false; 
	}
	else
	{
		document.getElementById("showMsgJob").innerHTML = "";
	}
}//Close function check	*/
	

$(document).ready(function() 
{	
		
		
		// Check Firstname
		$("#firstname").blur(function() 
		{ 
			if($(this).val() == '') 
			{
				//Blank or not
				$("#showMsgFN").html('<font id="error">Cannot be blank...</font>');
				document.getElementById("submit").setAttribute('disabled', 'disabled'); //Check Fail disible submit button
				return false; 
			}
			else
			{	//Validate special characters
				var FN = $(this).val();
				if(!(/^[A-Za-z]{2,15}$/.test(FN))) 
				{
					$("#showMsgFN").html('<font id="error">Just can be [A-Z a-z and _ ] only</font>');
					document.getElementById("submit").setAttribute('disabled', 'disabled'); //Check Fail disible submit button
				}
				else
				{
					$("#showMsgFN").html("<img src='images/tick.png' width='20px' height='20px' >");
					document.getElementById("submit").removeAttribute('disabled'); //Check True enable submit button
					return true;
				}
			}
		});//End Check Firstname
		
		// Check Lastname
		$("#lastname").blur(function() 
		{ 
			if($(this).val() == '') 
			{
				//Blank or not
				$("#showMsgLN").html('<font id="error">Cannot be blank...</font>'); 
				document.getElementById("submit").setAttribute('disabled', 'disabled'); //Check Fail disible submit button
				return false;
			}
			else
			{	//Validate special characters
				if(!(/^[A-Za-z]{2,15}$/.test($(this).val()))) 
				{
					$("#showMsgLN").html('<font id="error">Just can be [A-Z a-z and _ ] only</font>');
					document.getElementById("submit").setAttribute('disabled', 'disabled'); //Check Fail disible submit button
					return false;
				}
				else
				{
					$("#showMsgLN").html("<img src='images/tick.png' width='20px' height='20px' >");
					document.getElementById("submit").removeAttribute('disabled'); //Check True enable submit button
					return true;
				}
			}
		});//End Check Lastname
		
		// Check phone length
		$("#phone").blur(function() 
		{ 	//Validate special characters
			if($(this).val() == '') 
			{
				//Blank or not
				$("#showMsgPhone").html('<font id="error">Cannot be blank...</font>');
				document.getElementById("submit").setAttribute('disabled', 'disabled'); //Check Fail disible submit button
				return false; 
			}
			else
			{	//If Phone number is 10 digits like 0909123456
				if(($(this).val().length) <= 10) 
				{
						if(!(/^[0]{1}[9]{1}[0-9]{8}$/.test($(this).val()))) 
					{
						$("#showMsgPhone").html('<font id="error">Invalid phone number</font>');
						document.getElementById("submit").setAttribute('disabled', 'disabled'); //Check Fail disible submit button
						return false;
					}
					else
					{
						$("#showMsgPhone").html("<img src='images/tick.png' width='20px' height='20px' >");
						document.getElementById("submit").removeAttribute('disabled'); //Check True enable submit button
						return true;
					}
				}
				//If Phone number is 11 digits like 01286661234
				else if(($(this).val().length) >= 11) 
				{
					if(!(/^[0]{1}[1]{1}[0-9]{9,9}$/.test($(this).val()))) 
					{
						$("#showMsgPhone").html('<font id="error">Invalid phone number</font>');
						document.getElementById("submit").setAttribute('disabled', 'disabled'); //Check Fail disible submit button
						return false;
					}
					else
					{
						$("#showMsgPhone").html("<img src='images/tick.png' width='20px' height='20px' >");
						document.getElementById("submit").removeAttribute('disabled'); //Check True enable submit button
						return true;
					}
				}
			
			}
		});//End check phone length
		
		// Check DOB
		$("#DOB").blur(function() 
		{ 
			if($(this).val() == '') 
			{
				//Blank or not
				$("#showMsgDOB").html('<font id="error">Cannot be blank...</font>'); 
				document.getElementById("submit").setAttribute('disabled', 'disabled'); //Check Fail disible submit button
				return false;
			}
			else
			{	
			//Validate the age
				var DOB = document.getElementById("DOB").value;
				var year=Number(DOB.substr(0,4));
				var month=Number(DOB.substr(5,2));
				var day=Number(DOB.substr(8,2));
				var today=new Date();
				var age=today.getFullYear()-year;
				
				if(today.getMonth()<month || (today.getMonth()==month && today.getDate()<day) || (today.getMonth()==month && today.getDate()==day))
				{
					if(age < 12)
					{
						$("#showMsgDOB").html('<font id="error">Sorry your birthday is must be greater than 12</font>');
						document.getElementById("age").value=age;
						document.getElementById("submit").setAttribute('disabled', 'disabled'); //Check Fail disible submit button
						return false; 
					}
					else
					{
						$("#showMsgDOB").html("<img src='images/tick.png' width='20px' height='20px' >");
						document.getElementById("age").value=age;
						document.getElementById("submit").removeAttribute('disabled'); //Check True enable submit button
						return true;
					}
				}
			} // End else
		});//End Check DOB
		
		// Check ID length
		$("#idcard").blur(function() 
		{ 	//Validate special characters
			if($(this).val() == '') 
			{
				//Blank or not
				$("#showMsgIDcard").html('<font id="error">Cannot be blank...</font>');
				document.getElementById("submit").setAttribute('disabled', 'disabled'); //Check Fail disible submit button
				return false; 
			}
			else
			{	//Validate special characters
				if(!(/^[0]{1}[0-9]{8,8}$/.test($(this).val()))) 
				{
					$("#showMsgIDcard").html('<font id="error">Invalid ID No.</font>');
					document.getElementById("submit").setAttribute('disabled', 'disabled'); //Check Fail disible submit button
					return false; 
				}
				else
				{
					$("#showMsgIDcard").html("<img src='images/tick.png' width='20px' height='20px' >");
					document.getElementById("submit").removeAttribute('disabled'); //Check True enable submit button
					return true;
				}
			}
		});//End check ID length

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
});//End ready function



